package com.hangzhou.welbeing.welbeinginstrument.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.hangzhou.welbeing.welbeinginstrument.R;
import com.hangzhou.welbeing.welbeinginstrument.bean.ReadingEveryDayDateBean;
import com.hangzhou.welbeing.welbeinginstrument.config.RBConstants;
import com.hangzhou.welbeing.welbeinginstrument.inteface.OnRecyclerViewItemClickListener;

import java.util.ArrayList;
import java.util.List;

/**
 * 时间 2017 年 09 月 27.
 * 作者 Administrator  刘传华
 * 公司 杭州惟君医疗科技有限公司
 * 包名 com.hangzhou.welbeing.pregnant.welbeing_pregnant.fragement
 * 工程名 welbeing_pregnant
 */
public class ReadingEveryDayAdapter extends  RecyclerView.Adapter<ReadingEveryDayAdapter.ViewHolder> implements View.OnClickListener{
    private static final String TAG = "ReadingEveryDayAdapter";
    private OnRecyclerViewItemClickListener mOnItemClickListener = null;
    private List<ReadingEveryDayDateBean.DataBean> mlist = new ArrayList<>();
    private Context mcontext;
    public void setOnItemClickListener(OnRecyclerViewItemClickListener listener) {
        this.mOnItemClickListener = listener;
    }
    public ReadingEveryDayAdapter(List<ReadingEveryDayDateBean.DataBean> bean, Context context) {
        mlist.addAll(bean);
        mcontext = context;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_reading_every_daay_recyclerview,parent,false);
        ViewHolder viewHolder = new ViewHolder(view);
        view.setOnClickListener(this);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        holder.tv_content.setText(mlist.get(position).intro);
        Glide.with(mcontext).load(RBConstants.SERVER_URL+"/Public/Uploads/"+mlist.get(position).art_url).into(holder.iv_raw);
    }

    @Override
    public int getItemCount() {
        return mlist.size();
    }

    @Override
    public void onClick(View v) {
        if(mOnItemClickListener != null ){
            mOnItemClickListener.onItemClick(v);
        }
    }

    /**
     * 身体布局Holder
     */
    static class ViewHolder extends RecyclerView.ViewHolder {
        private  TextView tv_content;

        private ImageView iv_raw;
        public ViewHolder(View itemView) {
            super(itemView);
            tv_content =  (TextView) itemView.findViewById(R.id.item_daily_reading_tv_content);

            iv_raw =  (ImageView) itemView.findViewById(R.id.item_daily_reading_iv_raw);
        }
    }
}
